//
//  TestViewController.m
//  MyFamework
//
//  Created by carlos on 12-10-1.
//  Copyright (c) 2012年 carlos. All rights reserved.
//

#import "TestViewController.h"
#import "HttpService.h"
#import "ThreadMessage.h"
#import "TextCell.h"
#import <SDWebImage/UIImageView+WebCache.h>
#import "TableViewDataHandler.h"


@interface TestViewController ()
@property(nonatomic,weak)IBOutlet UITableView *myTableView;
@property(nonatomic,weak)IBOutlet UIImageView *iconV;


@end

@implementation TestViewController
#pragma mark 生命周期方法

- (void)viewDidLoad
{
    [super viewDidLoad];
    //通过nib文件的初始化
//    UIViewController.
    if (IOS7_OR_LATER) {
        self.edgesForExtendedLayout = UIRectEdgeNone;
        self.extendedLayoutIncludesOpaqueBars = NO;
        self.modalPresentationCapturesStatusBarAppearance = NO;
    }

}

- (BOOL)createCONav{
//    [self createCONavWithTitleName:@"test"];
    
    return NO;
}

- (void)loadView{
    [super loadView];
    [self.iconV setImageWithURL:[NSURL URLWithString:@"http://www.carloschen.cn:801/PocketAPI2/index.php/file/loadImage?imageName=0a01f8320a4748bdbcdd12eecf1c7dd7.jpg"]];
//    [HttpService instance];
//    return;
//    NSLog(@"%s,%@,%",__func__,NSStringFromSelector(_cmd),_cmd);
    //不通过nib文件初始化
    //填充数据
    _datas = [[NSMutableArray alloc]init];
    [_datas addObject:@"测试1"];
    [_datas addObject:@"测试2"];
    [_datas addObject:@"进入下一页"];
    [_datas addObject:@"显示弹出框"];
    [_datas addObject:@"测试1"];
    [_datas addObject:@"测试2"];
    [_datas addObject:@"进入下一页"];
    [_datas addObject:@"显示弹出框"];
    [_datas addObject:@"测试1"];
    [_datas addObject:@"测试2"];
    [_datas addObject:@"进入下一页"];
    [_datas addObject:@"显示弹出框"];
    [_datas addObject:@"测试1"];
    [_datas addObject:@"测试2"];
    [_datas addObject:@"进入下一页"];
    [_datas addObject:@"显示弹出框"];
    [_datas addObject:@"测试1"];
    [_datas addObject:@"测试2"];
    [_datas addObject:@"进入下一页"];
    [_datas addObject:@"显示弹出框"];

    //设计tableview
//    _myTableView = [[UITableView alloc]initWithFrame:CGRectMake(10, 100, kFBaseWidth-20, kFBaseHeight-20) style:UITableViewStyleGrouped];
    [_myTableView fillWithItems:_datas withFillCellBlock:nil withCOBaseCellClass:[TextCell class]];
    __block typeof(self)bSelf = self;

//    CLog(@"withBlock");
    [_myTableView setOnClickCellBlock:^(NSIndexPath *indexPath, id item) {
        int rowIndex = indexPath.row;
        switch (rowIndex) {
            case 0:{
                //点击了0 发送消息到后台线程
                ThreadMessage *threadMessage = [[ThreadMessage alloc]init];
                threadMessage.stringValue=@"我只是测试用的";
                threadMessage.returnUIMethod = @selector(returnTestUI:);
                threadMessage.interfaceDefine = kETest1;
                threadMessage.receiveUIBlock = ^(ThreadMessage *threadMessage){
                    if ([bSelf checkThreadMessageAndAlertError:threadMessage]) {
                        CLogb(@"received");
                        [bSelf hideProgressView];
                    }
                };
                [HttpService postMsgToHttp:threadMessage];
                [bSelf showProgressView];
                break;
            }
            case 1:{
                //点击了1 发送消息到后台线程
                ThreadMessage *threadMessage = [ThreadMessage createThreadWithReturnMethod:@selector(returnTestUI2:) withInterfaceDefine:kETest2];
                threadMessage.stringValue=@"我只是测试22";
                threadMessage.returnUIMethod = nil;
                [bSelf sendToHttp:threadMessage];
                [bSelf showProgressView];
                break;
            }
            case 2:{
                //            NextVC *vc = [[NextVC alloc]initWithNibName:@"NextVC" bundle:nil];
                break;
            }
            case 3:{
                [bSelf alertMsg:@"弹出"];
                break;
            }
            default:
                break;
        }

    }];

    [self.view addSubview:_myTableView];

}

- (void)returnTestUI:(ThreadMessage *)threadMessage{
    CLog(@"returnTestUI1=%@",threadMessage.stringValue);
    [self hideProgressView];
}
- (void)returnTestUI2:(ThreadMessage *)threadMessage{
    CLog(@"returnTestUI2=%@",threadMessage.stringValue);
//    InterfaceDefine1 t1 = Interface;
//    t1.u

    [self hideProgressView];
}
//返回默认的方法
- (void)returnDefault:(ThreadMessage *)threadMessage{
    CLog(@"returnDefault=%@",threadMessage.stringValue);
    [self hideProgressView];
}
#pragma mark 内存管理

- (void)dealloc{
    //要释放的变量
    _myTableView.delegate = nil;
    _myTableView.dataSource = nil;
}
@end
